package br.upe.dsc.caeto.simulation;

import br.upe.dsc.caeto.core.InvalidElementException;
import br.upe.dsc.caeto.core.cacheunit.CacheUnit;
import br.upe.dsc.caeto.core.cacheunit.CacheUnitSimple;
import br.upe.dsc.caeto.core.hierarchy.Hierarchy;

public class SimulationPoint {
	private Hierarchy hierarchy;
	
	public SimulationPoint(String hierarchyName,
			int associativityDl1, int lineSizeDl1, int cacheSizeDl1,
			int associativityDl2, int lineSizeDl2, int cacheSizeDl2,
			int associativityIl1, int lineSizeIl1, int cacheSizeIl1,
			int associativityIl2, int lineSizeIl2, int cacheSizeIl2,
			String powerSupply, String transistorTechnology) {
	
		hierarchy = new Hierarchy(hierarchyName,
				powerSupply, transistorTechnology);
		
		try {
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.DATA_CACHE_LEVEL_1, associativityDl1,
					lineSizeDl1, cacheSizeDl1));
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.DATA_CACHE_LEVEL_2, associativityDl2,
					lineSizeDl2, cacheSizeDl2));
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.INSTRUCTION_CACHE_LEVEL_1, associativityIl1,
					lineSizeIl1, cacheSizeIl1));
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.INSTRUCTION_CACHE_LEVEL_2, associativityIl2,
					lineSizeIl2, cacheSizeIl2));
		} catch (InvalidElementException e) {
			e.printStackTrace();
		}
	}
	
	public SimulationPoint(String hierarchyName,
			int associativityDl1, int lineSizeDl1, int cacheSizeDl1,
			int associativityIl1, int lineSizeIl1, int cacheSizeIl1,
			int associativityL2, int lineSizeL2, int cacheSizeL2,
			String powerSupply, String transistorTechnology) {
	
		hierarchy = new Hierarchy(hierarchyName,
				powerSupply, transistorTechnology);
		
		try {
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.DATA_CACHE_LEVEL_1, associativityDl1,
					lineSizeDl1, cacheSizeDl1));
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.INSTRUCTION_CACHE_LEVEL_1, associativityIl1,
					lineSizeIl1, cacheSizeIl1));
			hierarchy.addCacheUnit(new CacheUnitSimple(
					CacheUnit.UNIFIED_CACHE_LEVEL_2, associativityL2,
					lineSizeL2, cacheSizeL2));
		} catch (InvalidElementException e) {
			e.printStackTrace();
		}
	}
	
	public SimulationPoint(String hierarchyName,
			int associativity1, int lineSize1, int cacheSize1,
			int associativity2, int lineSize2, int cacheSize2,
			String powerSupply, String transistorTechnology) {
	
		hierarchy = new Hierarchy(hierarchyName,
				powerSupply, transistorTechnology);
		
		if (hierarchyName.equals(Hierarchy.HIERARCHY_3)) {
			try {
				hierarchy.addCacheUnit(new CacheUnitSimple(
						CacheUnit.UNIFIED_CACHE_LEVEL_1, associativity1,
						lineSize1, cacheSize1));
				hierarchy.addCacheUnit(new CacheUnitSimple(
						CacheUnit.UNIFIED_CACHE_LEVEL_2, associativity2,
						lineSize2, cacheSize2));
			} catch (InvalidElementException e) {
				e.printStackTrace();
			}
		} else if (hierarchyName.equals(Hierarchy.HIERARCHY_4)) {
			try {
				hierarchy.addCacheUnit(new CacheUnitSimple(
						CacheUnit.DATA_CACHE_LEVEL_1, associativity1,
						lineSize1, cacheSize1));
				hierarchy.addCacheUnit(new CacheUnitSimple(
						CacheUnit.INSTRUCTION_CACHE_LEVEL_1, associativity2,
						lineSize2, cacheSize2));
			} catch (InvalidElementException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Hierarchy getHierarchy() {
		return this.hierarchy;
	}
}
